#pragma once

#include <string>
#include <vector>
#include <ostream>


namespace book
{

class UriPath
{
public:

    class PushPopScope
    {
    public:
        PushPopScope(UriPath &path, const std::string &part)
            : path_(path) {
            path_.push(part);
        }

        ~PushPopScope() {
            path_.pop();
        }

    private:
        UriPath &path_;
    };

    UriPath() {}

    void pop() {
        if (!parts_.empty()) {
            parts_.pop_back();
        }
    }

    void push(const std::string &part) {
        parts_.push_back(part);
    }

    auto begin() const {
        return parts_.begin();
    }

    auto end() const {
        return parts_.end();
    }

private:
    std::vector<std::string> parts_;

    friend std::ostream &operator<<(std::ostream &out, const UriPath &obj) {
        for (const std::string &part : obj.parts_) {
            out << '/' << part;
        }
        return out;
    }
};

} // namespace book
